package thinkingInJava.generics;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

//: generics/ArrayOfGeneric.java

class Generic<T> {}

public class ArrayOfGeneric {
  static final int SIZE = 100;
  static Generic<Integer>[] gia;
  @SuppressWarnings("unchecked")
  public static void main(String[] args) {
    // Compiles; produces ClassCastException:
    //! gia = (Generic<Integer>[])new Object[SIZE];
    // Runtime type is the raw (erased) type:
	// 实际上可以强制 new Generic[SIZE] 可以存储任意类型，
	// 此法可以让它只存 Integer 类型
    gia = (Generic<Integer>[])new Generic[SIZE];
    System.out.println(gia.getClass().getSimpleName());
    gia[0] = new Generic<Integer>();
    //! gia[1] = new Object(); // Compile-time error
    // Discovers type mismatch at compile time:
    //! gia[2] = new Generic<Double>();
    
    List<String>[] llString = new List[10];
    llString[0] = new ArrayList<String>();
//    llString[1] = new LinkedList<Integer>(); 这样不行，但下面可以
    List[] ll = llString;
    ll[0] = new ArrayList<String>();
    ll[1] = new LinkedList<Integer>();
  }
} /* Output:
Generic[]
*///:~
